﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    public class XDataItemFilterConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            DataItemFilter dataFilter = new DataItemFilter();
            string value = System.Convert.ToString(valueNode.Attributes["Value"]);
            if (!string.IsNullOrWhiteSpace(value))
            {
                dataFilter.InitByText(value);
            }
            return dataFilter;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            Metadata.ValueNode valueNode = new Metadata.ValueNode("DataFilter");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", System.Convert.ToString(value));
            return valueNode;
        }
    }
}
